package com.awesome.uidemo.eventdispatch;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;

import com.awesome.common.util.log.ShowLogUtil;

/**
 * Author: JfangZ
 * Email: zhangjingfang@jeejio.com
 * Date: 2021/4/25 14:45
 * Description:我的LinearLayout
 */
public class MyLinearLayout extends LinearLayout {
    public MyLinearLayout(Context context) {
        super(context);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("ViewGroup dispatchTouchEvent ACTION_DOWN");
//                //父View的onTouchEvent
//                return false;
//                //消费
//                return true;
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("ViewGroup dispatchTouchEvent ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("ViewGroup dispatchTouchEvent ACTION_UP");
                break;
        }
        // 子View的dispatchTouchEvent
        boolean dispatchTouchEvent = super.dispatchTouchEvent(ev);
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("---return ViewGroup dispatchTouchEvent ACTION_DOWN "+dispatchTouchEvent);
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("---return ViewGroup dispatchTouchEvent ACTION_MOVE "+dispatchTouchEvent);
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("---return ViewGroup dispatchTouchEvent ACTION_UP "+dispatchTouchEvent);
                break;
        }
        return dispatchTouchEvent;
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("ViewGroup onInterceptTouchEvent ACTION_DOWN");
//                // 子View的dispatchTouchEvent
//                return false;
//                // 当前View的onTouchEvent
//                return true;
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("ViewGroup onInterceptTouchEvent ACTION_MOVE");
//                // 触发ACTION_CANCEL事件
//                 return true;
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("ViewGroup onInterceptTouchEvent ACTION_UP");
//                // 触发ACTION_CANCEL事件
//                return true;
                break;
        }
        boolean interceptTouchEvent = super.onInterceptTouchEvent(ev);
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("---return ViewGroup onInterceptTouchEvent ACTION_DOWN "+interceptTouchEvent);
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("---return ViewGroup onInterceptTouchEvent ACTION_MOVE "+interceptTouchEvent);
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("---return ViewGroup onInterceptTouchEvent ACTION_UP "+interceptTouchEvent);
                break;
        }
        return interceptTouchEvent;
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("ViewGroup onTouchEvent ACTION_DOWN");
//                // 父View的onTouchEvent
//                return false;
//                // 消费
//                return true;
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("ViewGroup onTouchEvent ACTION_MOVE");
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("ViewGroup onTouchEvent ACTION_UP");
                break;
            case MotionEvent.ACTION_CANCEL:
                ShowLogUtil.info("ViewGroup onTouchEvent ACTION_CANCEL");
                break;
        }
        // 父View的onTouchEvent
        boolean onTouchEvent = super.onTouchEvent(event);
        switch (event.getAction()){
            case MotionEvent.ACTION_DOWN:
                ShowLogUtil.info("---return ViewGroup onTouchEvent ACTION_DOWN "+onTouchEvent);
                break;
            case MotionEvent.ACTION_MOVE:
                ShowLogUtil.info("---return ViewGroup onTouchEvent ACTION_MOVE "+onTouchEvent);
                break;
            case MotionEvent.ACTION_UP:
                ShowLogUtil.info("---return ViewGroup onTouchEvent ACTION_UP "+onTouchEvent);
                break;
            case MotionEvent.ACTION_CANCEL:
                ShowLogUtil.info("---return ViewGroup onTouchEvent ACTION_CANCEL "+onTouchEvent);
                break;
        }
        return onTouchEvent;
    }


}
